package com.kit.data.kitopeso.base;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import androidx.viewbinding.ViewBinding;

public abstract class BaseBindingPopup<VB extends ViewBinding> extends PopupWindow {

    public VB binding;
    protected Context context;


    public BaseBindingPopup(Context context) {
        super(context);
        this.context=context;
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        this.context=context;
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup(View contentView) {
        super(contentView);
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup(int width, int height,Context context) {
        super(width, height);
        this.context=context;
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup(View contentView, int width, int height) {
        super(contentView, width, height);
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup(View contentView, int width, int height, boolean focusable) {
        super(contentView, width, height, focusable);
        initBinding();
        setCommonConfig();
    }

    public BaseBindingPopup() {
        initBinding();
        setCommonConfig();
    }


    protected abstract VB initViewBinding(LayoutInflater inflater);

    private void initBinding() {
        LayoutInflater inflater = LayoutInflater.from(context);
        binding = initViewBinding(inflater);
        setContentView(binding.getRoot());
    }


    @SuppressLint("ClickableViewAccessibility")
    private void setCommonConfig() {
        setTouchable(true);
        setOutsideTouchable(false);
        setTouchInterceptor((v, event) -> false);
        setBackgroundDrawable(new ColorDrawable(0x00000000));
    }

    @Override
    public void dismiss() {
        super.dismiss();
        binding = null;
    }

}
